<?php 

if (! defined('BASEPATH')) exit('No direct script access');

class cinema_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
    function get_by_id($cinema_id = FALSE)
    {
        if ($cinema_id === FALSE)
        {
            return FALSE;
        }
        
        $query = $this->db->where('id', $cinema_id)
                          ->get('cinema');
        if ($query->num_rows() == 1)
        {
            return $query->row();
        }
        else
        {
            return FALSE;
        }
    }
    
    function get_all($num = FALSE, $offset = FALSE) 
    {
        $query = $this->db->select('*,(SELECT name FROM branch WHERE id = cinema.branch_id) branch_name' )
                          ->get('cinema', $num, $offset);
        return $query->result();
    }
    
    
    
    function create($name = FALSE, $capacity = FALSE, $branch_id = FALSE)
    {
        if ($name === FALSE OR $capacity === FALSE OR $branch_id === FALSE )
        {
            return FALSE;
        }

        $cinema = array('name' => $name,
                         'capacity' => $capacity,
                         'branch_id' => $branch_id
                        );
        $this->db->insert('cinema', $cinema);
	    return TRUE;
        
    }
    
    function update($cinema_id = FAlSE , $name = FALSE, $capacity = FALSE, $branch_id = FALSE)
    {
        if ($branch_id === FALSE OR $name === FALSE OR $capacity === FALSE OR $branch_id === FALSE )
        {
            return FALSE;
        }
        $cinema = array('name' => $name,
                         'capacity' => $capacity,
                         'branch_id' => $branch_id
                        );
        $this->db->where('id', $cinema_id);
        $this->db->update('cinema', $cinema);
        return TRUE;
    }
    
    function delete($cinema_id = FALSE)
    {
        if ($cinema_id === FALSE)
        {
            return FALSE;
        }
        $this->db->where('id', $cinema_id);
        $this->db->delete('cinema');
        return TRUE;
    }
    
    function update_status($fixtures_id = FALSE, $status = FALSE)
    {
        if ($fixtures_id === FALSE OR $status === FALSE)
        {
            return FALSE;
        }
        $fixture = array('status' => $status);
        $this->db->where('id', $fixtures_id);
        $this->db->update('fixtures', $fixture);
        return TRUE;
    }
}
/* End of file fixture_model.php */
/* Location: ./system/application/models/fixture_model.php */